﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;

namespace DLL
{
	public class Controls
	{
		private System.Web.UI.Page page = new System.Web.UI.Page();
		private Config clsConfig = new Config();
		private Column.Component clsColumnComp;
		private UserGroup.Component clsUserGroupComp;
		private Department.Component clsDepartmentComp;
		private WebColumn.Component clsWebColumnComp;
		private CoursewareSort.Component clsCoursewareSortComp;
		private TrainingSort.Component clsTrainingSortComp;
		private Training.Component clsTrainingComp;
		private DepartmentLink.Component clsDepartmentLinkComp;
		private TrainingOrganization.Component clsTrainingOrganizationComp;

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <![CDATA[2014-8-15 11:07:39]]>
		/// <param name="page"></param>
		public Controls(System.Web.UI.Page page)
		{
			this.page = page;

			clsColumnComp = new Column.Component(page);
			clsUserGroupComp = new UserGroup.Component(page);
			clsDepartmentComp = new Department.Component(page);
			clsWebColumnComp = new WebColumn.Component(page);
			clsCoursewareSortComp = new CoursewareSort.Component(page);
			clsTrainingSortComp = new TrainingSort.Component(page);
			clsTrainingComp = new Training.Component(page);
			clsDepartmentLinkComp = new DepartmentLink.Component(page);
			clsTrainingOrganizationComp = new TrainingOrganization.Component(page);
		}

		#region 根据栏目的上下级排序，显示所有栏目
		/// <summary>
		/// 根据栏目的上下级排序，显示所有栏目
		/// </summary>
		/// <![CDATA[2014-8-9 11:49:05]]>
		/// <param name="ddl"></param>
		public void ColumnOrder(DropDownList ddl)
		{
			Column.Component clsColumnComp = new Column.Component(page);
			List<Column.Entity> listColumn = new List<Column.Entity>();

			listColumn = clsColumnComp.QueryAllOrder();
			clsColumnComp.AddGradeInName(listColumn, "|", "--");

			for (int i = 0; i < listColumn.Count; i++)
			{
				ListItem lItem = new ListItem();

				lItem.Text = listColumn[i].ColumnName;
				lItem.Value = listColumn[i].ID.ToString();

				ddl.Items.Add(lItem);
			}
		}
		#endregion 根据栏目的上下级排序，显示所有栏目
		#region 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项
		/// <summary>
		/// 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项
		/// </summary>
		/// <![CDATA[2014-8-9 15:18:29]]>
		/// <param name="ddl"></param>
		public void ColumnWithNoParentOrder(DropDownList ddl)
		{
			ColumnOrder(ddl);

			ListItem lItem = new ListItem();

			lItem.Text = "无";
			lItem.Value = clsConfig.nColumn_NoParent.ToString();

			ddl.Items.Insert(0, lItem);
		}
		#endregion 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项
		#region 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项，增加全部项
		/// <summary>
		/// 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项，增加全部项
		/// </summary>
		/// <![CDATA[2014-8-10 10:32:13]]>
		/// <param name="ddl"></param>
		public void ColumnWithAllNoParentOrder(DropDownList ddl)
		{
			ColumnWithNoParentOrder(ddl);

			ListItem lItem = new ListItem();

			lItem.Text = "全部";
			lItem.Value = clsConfig.nQueryConditionIntAll.ToString();
			ddl.Items.Insert(0, lItem);
		}
		#endregion 根据栏目的上下级排序，显示所有栏目，增加没有上级栏目项，增加全部项
		#region 查询所有栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项
		/// <summary>
		/// 查询所有栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项
		/// </summary>
		/// <![CDATA[2014-8-10 11:05:12]]>
		/// <param name="cbl"></param>
		/// <param name="strColumnIDs"></param>
		public void SetAllColumnsToCheckBoxList(CheckBoxList cbl, string strColumnIDs)
		{
			List<Column.Entity> list = new List<Column.Entity>();

			//list = clsColumnComp.QueryAll();
			list = clsColumnComp.QueryAllOrder();
			clsColumnComp.AddGradeInName(list, "| ", "--");

			cbl.DataSource = list;
			cbl.DataTextField = "ColumnName";
			cbl.DataValueField = "ID";
			cbl.DataBind();

			for (int i = 0; i < cbl.Items.Count; i++)
			{
				if (TonyNet4V1.CommonFunction.FindString(strColumnIDs, cbl.Items[i].Value.Trim()))
				{
					cbl.Items[i].Selected = true;
				}
			}
		}
		#endregion 查询所有栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项

		#region 查询所有前台栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项
		/// <summary>
		/// 查询所有前台栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项
		/// </summary>
		/// <![CDATA[2014-8-13 17:35:03]]>
		/// <param name="cbl"></param>
		/// <param name="strColumnIDs"></param>
		public void SetNoInheritWebColumnsToCheckBoxList(CheckBoxList cbl, string strColumnIDs)
		{
			List<WebColumn.Entity> list = new List<WebColumn.Entity>();

			//list = clsColumnComp.QueryAll();
			list = clsWebColumnComp.QueryNoInheritColumn();
			clsWebColumnComp.AddGradeInName(list, "| ", "--");

			cbl.DataSource = list;
			cbl.DataTextField = "ColumnName";
			cbl.DataValueField = "ID";
			cbl.DataBind();

			for (int i = 0; i < cbl.Items.Count; i++)
			{
				if (TonyNet4V1.CommonFunction.FindString(strColumnIDs, cbl.Items[i].Value.Trim()))
				{
					cbl.Items[i].Selected = true;
				}
			}
		}
		#endregion 查询所有前台栏目，用CheckBoxList绑定显示，并根据strColumnIDs的值设置选中项
		#region 用下拉列表显示所有前台栏目
		/// <summary>
		/// 显示所有前台栏目
		/// </summary>
		/// <![CDATA[2014-8-12 03:37:04]]>
		/// <param name="ddl"></param>
		public void ShowWebColumn(DropDownList ddl)
		{
			List<WebColumn.Entity> list = new List<WebColumn.Entity>();

			list = clsWebColumnComp.QueryAllOrder();
			clsWebColumnComp.AddGradeInName(list, "|", "--");

			ddl.DataSource = list;
			ddl.DataTextField = "ColumnName";
			ddl.DataValueField = "ID";
			ddl.DataBind();

			ListItem lItem = new ListItem();

			lItem.Text = clsConfig.strColumn_NoParent;
			lItem.Value = clsConfig.nColumn_NoParent.ToString();

			ddl.Items.Insert(0, lItem);
		}
		#endregion 用下拉列表显示所有前台栏目
		#region 显示栏目是否继承权限下拉列表
		/// <summary>
		/// 显示栏目是否继承权限下拉列表
		/// </summary>
		/// <![CDATA[2014-8-13 16:48:25]]>
		/// <param name="ddl"></param>
		public void ShowInherit(DropDownList ddl)
		{
			ListItem lItemInherit = new ListItem();
			ListItem lItemNoINherit = new ListItem();

			lItemInherit.Text = clsConfig.strColumn_Inherit;
			lItemInherit.Value = clsConfig.nColumn_Inherit.ToString();

			lItemNoINherit.Text = clsConfig.strColumn_NoInHerit;
			lItemNoINherit.Value = clsConfig.nColumn_NoInherit.ToString();

			ddl.Items.Add(lItemNoINherit);
			ddl.Items.Add(lItemInherit);
		}
		#endregion 显示栏目是否继承权限下拉列表
		#region 显示所有前台栏目，带有“全部”
		/// <summary>
		/// 显示所有前台栏目，带有“全部”
		/// </summary>
		/// <![CDATA[2014-8-12 03:39:00]]>
		/// <param name="ddl"></param>
		public void ShowWebColumnWithAll(DropDownList ddl)
		{
			ShowWebColumn(ddl);
			AddIntQueryAllListItem(ddl);
		}
		#endregion 显示所有前台栏目，带有“全部”
		#region 用CheckBox显示用户有权限上传文件的前台栏目
		/// <summary>
		/// 用CheckBox显示用户有权限上传文件的前台栏目
		/// </summary>
		/// <![CDATA[2014-8-17 16:44:09]]>
		/// <param name="strWebColumnIDs">用户权限</param>
		/// <param name="cbl">显示栏目的Checkbox</param>
		public void ShowHaveRightWebColumn(string strWebColumnIDs, CheckBoxList cbl)
		{
			List<WebColumn.Entity> list = new List<WebColumn.Entity>();

			list = clsWebColumnComp.QueryByRight(strWebColumnIDs);
			clsWebColumnComp.AddGradeInName(list, "|", "--");

			cbl.DataSource = list;
			cbl.DataTextField = "ColumnName";
			cbl.DataValueField = "ID";
			cbl.DataBind();

		}
		#endregion 用CheckBox显示用户有权限上传文件的前台栏目

		#region 设置地址下来列表
		/// <summary>
		/// 设置地址下来列表
		/// </summary>
		/// <![CDATA[2014-8-10 15:34:10]]>
		/// <param name="ddl"></param>
		public void SetLinkDropDownList(DropDownList ddl)
		{

			List<String> list = TonyNet4V1.CommonFunction.GetFileByPathExtension(HttpContext.Current.Server.MapPath("./"), "aspx");

			for (int i = 0; i < list.Count; i++)
			{
				ddl.Items.Add(new ListItem(list[i], list[i]));
			}

			ddl.Items.Insert(0, new ListItem("无", ""));
		}
		#endregion 设置地址下来列表

		#region 用下拉列表显示所有用户组
		/// <summary>
		/// 用下拉列表显示所有用户组
		/// </summary>
		/// <![CDATA[2014-8-10 15:46:07]]>
		/// <param name="ddl"></param>
		public void ShowUserGroup(DropDownList ddl)
		{
			ddl.DataSource = clsUserGroupComp.QueryAll();
			ddl.DataTextField = "UserGroupName";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示所有用户组

		/// <summary>
		/// 用下拉列表显示所有用户组，并增加全部查询项
		/// </summary>
		/// <![CDATA[2014-8-10 16:57:49]]>
		/// <param name="ddl"></param>
		public void ShowUserGroupWithAll(DropDownList ddl)
		{
			ShowUserGroup(ddl);

			AddIntQueryAllListItem(ddl);
		}

		#region 用下拉列表显示所有单位
		/// <summary>
		/// 用下拉列表显示所有单位
		/// </summary>
		/// <![CDATA[2014-8-15 11:08:48]]>
		/// <param name="ddl"></param>
		public void ShowAllDepartment(DropDownList ddl)
		{
			List<Department.Entity> list = new List<Department.Entity>();

			list = clsDepartmentComp.QueryAllOrder();
			clsDepartmentComp.AddGradeInName(list, "|", "--");

			ddl.DataSource = list;
			ddl.DataTextField = "DepartmentName";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示所有单位
		#region 用下拉列表显示所有单位，带有“无”单位一项
		/// <summary>
		/// 用下拉列表显示所有单位，带有“无”单位一项
		/// </summary>
		/// <![CDATA[2014-8-11 16:22:57]]>
		/// <param name="ddl"></param>
		public void ShowDepartment(DropDownList ddl)
		{
			List<Department.Entity> list = new List<Department.Entity>();

			list = clsDepartmentComp.QueryAllOrder();
			clsDepartmentComp.AddGradeInName(list, "|", "--");

			ddl.DataSource = list;
			ddl.DataTextField = "DepartmentName";
			ddl.DataValueField = "ID";
			ddl.DataBind();

			ListItem lItem = new ListItem();

			lItem.Text = clsConfig.strDepartment_NoParent;
			lItem.Value = clsConfig.nDepartment_NoParent.ToString();

			ddl.Items.Insert(0, lItem);
		}
		#endregion
		#region 用下拉列表显示所有单位，带有全部选项
		/// <summary>
		/// 用下拉列表显示所有单位，带有全部选项
		/// </summary>
		/// <![CDATA[2014-8-11 23:34:11]]>
		/// <param name="ddl"></param>
		public void ShowDepartmentWithAll(DropDownList ddl)
		{
			ShowDepartment(ddl);

			AddIntQueryAllListItem(ddl);
		}
		#endregion 用下拉列表显示所有单位，带有全部选项

		#region 用下拉列表显示所有课件类型
		/// <summary>
		/// 用下拉列表显示所有课件类型
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowCoursewareSort(DropDownList ddl)
		{
			ddl.DataSource = clsCoursewareSortComp.QueryAll();
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示所有课件类型

		#region 用下拉列表显示所有培训类型
		/// <summary>
		/// 用下拉列表显示所有培训类型
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingSort(DropDownList ddl)
		{
			ddl.DataSource = clsTrainingSortComp.QueryAll();
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示所有培训类型
		#region 用下拉列表显示所有培训类型（带有全部）
		/// <summary>
		/// 用下拉列表显示所有培训类型（带有全部）
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingSortWithAll(DropDownList ddl)
		{
			ShowTrainingSort(ddl);
			AddIntQueryAllListItem(ddl);
		}
		#endregion 用下拉列表显示所有培训类型（带有全部）

		#region 用下拉列表显示培训类型（线上培训还是线下培训）
		/// <summary>
		/// 用下拉列表显示培训类型（线上培训还是线下培训）
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingType(DropDownList ddl)
		{
			ListItem lItemOnLine = new ListItem();
			ListItem lItemOffLine = new ListItem();

			lItemOnLine.Text = clsConfig.strArrTrainingType[clsConfig.nTrainingType_OnLine];
			lItemOnLine.Value = clsConfig.nTrainingType_OnLine.ToString();

			lItemOffLine.Text = clsConfig.strArrTrainingType[clsConfig.nTrainingType_OffLine];
			lItemOffLine.Value = clsConfig.nTrainingType_OffLine.ToString();

			ddl.Items.Add(lItemOnLine);
			ddl.Items.Add(lItemOffLine);
		}
		#endregion 用下拉列表显示培训类型（线上培训还是线下培训）

		#region 用下拉列表显示本人添加的处在创建阶段的培训班
		/// <summary>
		/// 用下拉列表显示本人添加的处在创建阶段的培训班
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowMySelfBuildTraining(DropDownList ddl, int nUserID)
		{
			ddl.DataSource = clsTrainingComp.QueryMySelfBulidTraining(nUserID);
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示本人添加的处在创建阶段的培训班
		#region 用下拉列表显示本人能添加课件的培训班
		/// <summary>
		/// 用下拉列表显示本人能添加课件的培训班
		/// </summary>
		/// <param name="nUserID"></param>
		public void ShowMySelfCanAddCoursewareTraining(DropDownList ddl, int nUserID)
		{
			ddl.DataSource = clsTrainingComp.QueryMySelfCanAddCoursewareTraining(nUserID);
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示本人能添加课件的培训班
		#region 用下拉列表显示所有培训班，带上“全部”查询项
		/// <summary>
		/// 用下拉列表显示所有培训班，带上“全部”查询项
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowAllTrainingWithAll(DropDownList ddl)
		{
			ddl.DataSource = clsTrainingComp.QueryAll();
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();

			AddIntQueryAllListItem(ddl);
		}
		#endregion 用下拉列表显示所有培训班，带上“全部”查询项
		#region 根据查询条件查找培训班，用下拉列表显示，并带上“全部”查询项
		/// <summary>
		/// 根据查询条件查找培训班，用下拉列表显示，并带上“全部”查询项
		/// </summary>
		/// <param name="ddl"></param>
		/// <param name="clsTrainingQuery"></param>
		public void ShowTrainingWithAll(DropDownList ddl, Training.QueryEntity clsTrainingQuery)
		{
			ddl.DataSource = clsTrainingComp.Query(clsTrainingQuery);
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();

			AddIntQueryAllListItem(ddl);
		}
		#endregion 根据查询条件查找培训班，用下拉列表显示，并带上“全部”查询项
		#region 查询本人添加的培训班，用下拉列表显示，并带有“全部”项，用于查询
		/// <summary>
		/// 查询本人添加的培训班，用下拉列表显示，并带有“全部”项，用于查询
		/// </summary>
		/// <param name="ddl"></param>
		/// <param name="nUserID"></param>
		public void ShowTrainingWithAllByUserID(DropDownList ddl, int nUserID)
		{
			ddl.DataSource = clsTrainingComp.QueryMySelfBulidTraining(nUserID);
			ddl.DataTextField = "Name";
			ddl.DataValueField = "ID";
			ddl.DataBind();

			AddIntQueryAllListItem(ddl);
		}
		#endregion 查询本人添加的培训班，用下拉列表显示，并带有“全部”项，用于查询

		#region 用下拉列表显示供求信息类别
		/// <summary>
		/// 用下拉列表显示供求信息类别
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowSupplyDemandType(DropDownList ddl)
		{
			ListItem lItemSupply = new ListItem();
			ListItem lItemDemand = new ListItem();

			lItemSupply.Text = clsConfig.strArrSupplyDemandType[clsConfig.nSupplyDemandType_Supply];
			lItemSupply.Value = clsConfig.nSupplyDemandType_Supply.ToString();

			lItemDemand.Text = clsConfig.strArrSupplyDemandType[clsConfig.nSupplyDemandType_Demand];
			lItemDemand.Value = clsConfig.nSupplyDemandType_Demand.ToString();

			ddl.Items.Add(lItemDemand);
			ddl.Items.Add(lItemSupply);
		}
		#endregion 用下拉列表显示供求信息类别

		#region 用下拉列表显示没有上级单位链接的单位链接
		/// <summary>
		/// 用下拉列表显示没有上级单位链接的单位链接
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowNoParentDepartmentLink(DropDownList ddl)
		{
			ddl.DataSource = clsDepartmentLinkComp.QueryNoParent();
			ddl.DataTextField = "DepartmentName";
			ddl.DataValueField = "ID";
			ddl.DataBind();
		}
		#endregion 用下拉列表显示没有上级单位链接的单位链接
		#region 用下拉列表显示没有上级单位链接的单位链接，带有“无”选项
		/// <summary>
		/// 用下拉列表显示没有上级单位链接的单位链接，带有“无”选项
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowNoParentDepartmentLinkWithNoParentItem(DropDownList ddl)
		{
			ListItem lItem = new ListItem();

			ShowNoParentDepartmentLink(ddl);
			lItem.Text = clsConfig.strDepartmentLink_NoParent;
			lItem.Value = clsConfig.nDepartmentLink_NoParent.ToString();

			ddl.Items.Insert(0, lItem);
		}
		#endregion 用下拉列表显示没有上级单位链接的单位链接，带有“无”选项

		#region 用下拉列表显示培训班所处的进度
		/// <summary>
		/// 用下拉列表显示培训班所处的进度
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingState(DropDownList ddl)
		{
			for (int i = 1; i < clsConfig.strArrTrainingState.Length; i++)
			{
				ListItem lItem = new ListItem();

				lItem.Text = clsConfig.strArrTrainingState[i];
				lItem.Value = i.ToString();

				ddl.Items.Add(lItem);
			}
		}
		#endregion 用下拉列表显示培训班所处的进度
		#region 用下拉列表显示培训班所处的进度，带有全部
		/// <summary>
		/// 用下拉列表显示培训班所处的进度
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingStateWithAll(DropDownList ddl)
		{
			ShowTrainingState(ddl);
			AddIntQueryAllListItem(ddl);
		}
		#endregion 用下拉列表显示培训班所处的进度，带有全部

		#region 查询权限
		/// <summary>
		/// 用下拉列表显示所有查询权限
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowQueryRight(DropDownList ddl)
		{
			ListItem lItemAll = new ListItem();
			ListItem lItemDepartment = new ListItem();
			ListItem lItemMySelf = new ListItem();

			lItemAll.Text = clsConfig.strArrQueryRight[clsConfig.nQueryRight_All];
			lItemAll.Value = clsConfig.nQueryRight_All.ToString();

			lItemDepartment.Text = clsConfig.strArrQueryRight[clsConfig.nQueryRight_Department];
			lItemDepartment.Value = clsConfig.nQueryRight_Department.ToString();

			lItemMySelf.Text = clsConfig.strArrQueryRight[clsConfig.nQueryRight_MySelf];
			lItemMySelf.Value = clsConfig.nQueryRight_MySelf.ToString();

			ddl.Items.Add(lItemAll);
			ddl.Items.Add(lItemDepartment);
			ddl.Items.Add(lItemMySelf);
		}
		#endregion 查询权限

		#region 培训机构
		/// <summary>
		/// 用下拉列表显示所有培训机构
		/// </summary>
		/// <param name="ddl"></param>
		public void ShowTrainingOrganization(DropDownList ddl)
		{
			ddl.DataSource = clsTrainingOrganizationComp.QueryAll();
			ddl.DataValueField = "ID";
			ddl.DataTextField = "Name";
			ddl.DataBind();
		}
		#endregion

		#region 添加查询全部项
		/// <summary>
		/// 添加整型的全部查询项
		/// </summary>
		/// <![CDATA[2014-8-10 16:55:49]]>
		/// <param name="ddl"></param>
		private void AddIntQueryAllListItem(DropDownList ddl)
		{
			ListItem lItem = new ListItem();

			lItem.Text = "全部";
			lItem.Value = clsConfig.nQueryConditionIntAll.ToString();
			ddl.Items.Insert(0, lItem);
		}
		/// <summary>
		/// 添加字符串型的全部查询项
		/// </summary>
		/// <![CDATA[2014-8-10 16:56:51]]>
		/// <param name="ddl"></param>
		private void AddStringQueryAllListItem(DropDownList ddl)
		{
			ListItem lItem = new ListItem();

			lItem.Text = "全部";
			lItem.Value = clsConfig.strQueryConditionStringAll.ToString();
			ddl.Items.Insert(0, lItem);
		}
		#endregion 添加查询全部项
	}
}
